﻿// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证（版本 2.0）进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动！任何基于本项目二次开发而产生的一切法律纠纷和责任，我们不承担任何责任！

using Newtonsoft.Json;
using Sinc.ERP.Core.Enum;

namespace Sinc.ERP.Application;

/// <summary>
/// 实体卡输出参数
/// </summary>
public class ProductCardOutput
{
    /// <summary>
    /// 主键Id
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 产品Id
    /// </summary>
    public long ProductId { get; set; }

    public string ProductLabel { get; set; }

    /// <summary>
    /// 导入批次号
    /// </summary>
    public string BatchNumber { get; set; }

    /// <summary>
    /// ICCID
    /// </summary>
    public string Code { get; set; }

    /// <summary>
    /// 完整ICCID
    /// </summary>
    public string FullCode { get; set; }

    /// <summary>
    /// 校验码
    /// </summary>
    public string? Passcode { get; set; }

    /// <summary>
    /// 成本价
    /// </summary>
    public decimal CostPrice { get; set; }

    /// <summary>
    /// 有效期
    /// </summary>
    public DateTime ExpirationDate { get; set; }

    /// <summary>
    /// 状态
    /// </summary>
    public ProductCardStatusEnum Status { get; set; }

    /// <summary>
    /// 所属客户
    /// </summary>
    public long CustomerId { get; set; }

    public string CustomerLabel { get; set; }

    /// <summary>
    /// 软删除
    /// </summary>
    public bool IsDelete { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime? CreateTime { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdateTime { get; set; }

    /// <summary>
    /// 创建者Id
    /// </summary>
    public long? CreateUserId { get; set; }

    /// <summary>
    /// 创建者姓名
    /// </summary>
    public string? CreateUserName { get; set; }

    /// <summary>
    /// 修改者Id
    /// </summary>
    public long? UpdateUserId { get; set; }

    /// <summary>
    /// 修改者姓名
    /// </summary>
    public string? UpdateUserName { get; set; }
}

/// <summary>
/// 实体卡数据导入模板实体
/// </summary>
public class ExportProductCardOutput : ImportProductCardInput
{
    [ImporterHeader(IsIgnore = true)]
    [ExporterHeader("*激活地址", Format = "", Width = 100, IsBold = true)]
    public string Url { get; set; }

    [ImporterHeader(IsIgnore = true)]
    [ExporterHeader("*客户名称", Format = "", Width = 20, IsBold = true)]
    public string CustomerLabel { get; set; }

    [ImporterHeader(IsIgnore = true)]
    [ExporterHeader(IsIgnore = true)]
    public override string Error { get; set; }
}

public class CustomerExportOutput
{
    /// <summary>
    /// 记录Id
    /// </summary>
    [ImporterHeader(IsIgnore = true)]
    [ExporterHeader(IsIgnore = true)]
    public virtual long Id { get; set; }

    [ImporterHeader(IsIgnore = true)]
    [ExporterHeader(IsIgnore = true)]
    public long? ProductId { get; set; }

    /// <summary>
    /// 产品名称
    /// </summary>
    [ImporterHeader(Name = "*产品名称")]
    [ExporterHeader("*产品名称", Format = "", Width = 25, IsBold = true)]
    public string? ProductName { get; set; }

    /// <summary>
    /// ICCID
    /// </summary>
    [ImporterHeader(Name = "*ICCID")]
    [ExporterHeader("*ICCID", Format = "", Width = 25, IsBold = true)]
    public string Code { get; set; }

    /// <summary>
    /// 状态 关联值
    /// </summary>
    [ImporterHeader(IsIgnore = true)]
    [ExporterHeader(IsIgnore = true)]
    public ProductCardStatusEnum? Status { get; set; }

    /// <summary>
    /// 状态 文本
    /// </summary>
    [Dict("ProductCardStatusEnum")]
    [ImporterHeader(Name = "*状态")]
    [ExporterHeader("*状态", Format = "", Width = 25, IsBold = true)]
    public string StatusLabel { get; set; }

    [ImporterHeader(IsIgnore = true)]
    [ExporterHeader("*激活地址", Format = "", Width = 100, IsBold = true)]
    public string Url { get; set; }
}

public class ActivateProductCardOutput
{
    public int SuccessCount { get; set; }

    public int FailureCount => this.ErrorList?.Count ?? 0;

    [JsonIgnore]
    public IList<ActivateProductCardErrorOutput> ErrorList { get; set; } = new List<ActivateProductCardErrorOutput>();

    public void AddResult(string code, bool success, string message)
    {
        if (success)
        {
            this.SuccessCount++;
            return;
        }

        this.ErrorList.Add(new ActivateProductCardErrorOutput { Code = code, Message = message });
    }
}

public class ActivateProductCardErrorOutput
{
    public string Code { get; set; }

    public string Message { get; set; }
}

public class FillInProductCardOutput
{
    public int SuccessCount { get; set; }

    public int FailureCount { get; set; }

    private IList<string> _missCodeList;
    public IList<string> MissCodeList
    {
        get => this._missCodeList = this._missCodeList ?? new List<string>();
        set => this._missCodeList = value;
    }
}